<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@
	request.setCharacterEncoding("GB2312");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>注册</title>
</head>
<script type="text/javascript" src="static/js/jquery-3.2.1.js"></script>


<body>
	<h2 align="center">注册百度账号</h2>
	<hr lang="max" />
	<form action="zhuce" method="post" onsubmit="return onsub()">
		<table align="center">
			<tr>
				<td>用&nbsp;&nbsp;户&nbsp;&nbsp;名:</td>
				<td><input id="username" name="uname" type="text"
					onblur="checkUser()" /><span id="checkUN"></span></td>
			</tr>
			<tr>
				<td>公司名称:</td>
				<td><input id="coName" name="coName" type="text" /></td>
			</tr>
			<tr>
				<td>公司税号:</td>
				<td><input id="coShui" name="coShui" type="text" /></td>
			</tr>
			<tr>
				<td>密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:</td>
				<td><input id="password" name="upwd" type="password"
					onblur="checkpwd()" /><span id="checkUP"></span></td>
			</tr>
			<tr>
				<td>确认密码:</td>
				<td><input id="repassword" name="repwd" type="password"
					onblur="checkrepwd()" /><span id="checkREUP"></span></td>
			</tr>
			<tr>
				<td colspan="2" align="center"><input value="确认注册"
					type="submit" /></td>
			</tr>
		</table>
	</form>

	<script type="text/javascript">
		//阻止提交参数
		var uresult = false;
		var presult = false;
		var represult = false;
		//确认用户名
		function checkUser() {
			var uname = $("#username").val();
			$.ajax({
				type : "post",
				url : 'checkUser',
				data : "uname=" + uname,
				success : function(data) {
					ine(data);
				}
			});
		}
		//用户名状态
		function ine(data) {
			if (data == 1) {
				document.getElementById("checkUN").innerHTML = "<b style='color:red'>用户名已存在</b>";
				uresult = false;
			} else if (data == 2) {
				document.getElementById("checkUN").innerHTML = "<b style='color:red'>用户名不能为空</b>";
				uresult = false;
			} else if (data == 3) {
				document.getElementById("checkUN").innerHTML = "<b style='color:green'>用户名可用</b>"
				uresult = true;
			} else if (data == 0) {
				document.getElementById("checkUN").innerHTML = "<b style='color:red'>ajax成功返回值为空</b>"
			} else {
				document.getElementById("checkUN").innerHTML = "<b style='color:red'>未知错误</b>"
			}
		}
		//密码是否为空
		function checkpwd() {
			var pwd = $("#password").val();
			if (pwd == "") {
				document.getElementById("checkUP").innerHTML = "<b style='color:red'>密码不能为空</b>";
				presult = false;
			} else if (pwd.length > 16) {
				document.getElementById("checkUP").innerHTML = "<b style='color:red'>密码必须小于16位</b>";
				presult = false;
			} else if (pwd.length < 6) {
				document.getElementById("checkUP").innerHTML = "<b style='color:red'>密码必须大于6位</b>";
				presult = false;
			} else {
				document.getElementById("checkUP").innerHTML = "<b style='color:green'>密码可用</b>";
				presult = true;
			}
		}
		//确认密码状态
		function checkrepwd() {
			var pwd = $("#password").val();
			var repwd = $("#repassword").val();
			if (pwd == repwd) {
				document.getElementById("checkREUP").innerHTML = "<b style='color:green'>密码确认完成</b>";
				represult = true;
			} else {
				document.getElementById("checkREUP").innerHTML = "<b style='color:red'>两次密码不相同</b>";
				represult = false;
			}
		}
		//允许提交
		function onsub() {
			if (uresult == true && presult == true && represult == true) {
				return true;
			} else {
				alert("意料之外的错误")
				return false;
			}
		}
	</script>
</body>
</html>